package org.rsbot.log;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import org.rsbot.util.StringUtil;

public class LogFormatter extends Formatter
{
  private static final String LINE_SEPARATOR = System.getProperty("line.separator");
  public boolean appendNewLine;

  public LogFormatter()
  {
    this(true);
  }

  public LogFormatter(boolean paramBoolean) {
    this.appendNewLine = paramBoolean;
  }

  public String format(LogRecord paramLogRecord)
  {
    StringBuilder localStringBuilder = new StringBuilder().append("[").append(paramLogRecord.getLevel().getName()).append("] ").append(new Date(paramLogRecord.getMillis())).append(": ").append(paramLogRecord.getLoggerName()).append(": ").append(paramLogRecord.getMessage()).append(StringUtil.throwableToString(paramLogRecord.getThrown()));

    if (this.appendNewLine) {
      localStringBuilder.append(LINE_SEPARATOR);
    }
    return localStringBuilder.toString();
  }

  public String formatMessage(LogRecord paramLogRecord)
  {
    return String.format(paramLogRecord.getMessage(), new Object[0]);
  }

  public String formatTimestamp(LogRecord paramLogRecord) {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("hh:mm:ss");
    return new StringBuilder().append("[").append(localSimpleDateFormat.format(Long.valueOf(paramLogRecord.getMillis()))).append("]").toString();
  }

  public String formatClass(LogRecord paramLogRecord) {
    String str1 = "...";
    String[] arrayOfString = paramLogRecord.getLoggerName().split("\\.");
    String str2 = arrayOfString[(arrayOfString.length - 1)];
    int i = 16;

    return String.format(str2.length() > i ? new StringBuilder().append(str2.substring(0, i - str1.length())).append(str1).toString() : str2, new Object[0]);
  }

  public String formatError(LogRecord paramLogRecord)
  {
    return StringUtil.throwableToString(paramLogRecord.getThrown());
  }
}